package org.xhy.oap.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping()
public class ElasticsearchQueryController {

    @Autowired
    private ElasticsearchQueryService elasticsearchQueryService;

    // 查询索引 "test" 中的数据
    @GetMapping("")
    public List<Map<String, Object>> search(@RequestParam(value = "traceId", required = false) String traceId) {
        try {
            if (traceId != null && !traceId.isEmpty()) {
                // 如果 traceId 存在，则查询特定 traceId
                return elasticsearchQueryService.searchByTraceId("test", traceId);
            } else {
                // 如果没有传入 traceId，则查询所有数据
                return elasticsearchQueryService.searchAllData("test");
            }
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }


}
